package com.ky.manage.utils.log;

import android.os.Environment;

import java.io.File;

/**
 * @author lyc
 * 在需要抓取Log时在用户SD卡根目录创建LogConfig.properties配置文件，即可输出log到文件
 * logcat true 输出log开关
 * filelog true 输出到文件开关
 */
public class LogHelperManager {

    /**
     * 主路径
     */
    private static final String MAIN_DIR = Environment.getExternalStorageDirectory() + "/lxkj/log";
    /**
     * 保存Log的文件
     */
    private static final String LOG_FILE = MAIN_DIR + "/education_trace_log.txt";
    private static volatile LogHelperManager INSTANCE;

    private LogHelperManager() {
    }

    public static LogHelperManager getInstance() {
        if (INSTANCE == null) {
            synchronized (LogHelperManager.class) {
                if (INSTANCE == null) {
                    INSTANCE = new LogHelperManager();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * 初始化log配置
     * log文件路径，必须是完整的全路径
     */
    public void init() {
        createLogFile();
    }

    private boolean createLogFile() {
        boolean ret = false;
        File file = new File(LOG_FILE);
        try {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            ret = file.createNewFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }

    String getLogFilePath() {
        return LOG_FILE;
    }
}
